#!/bin/sh
# 
# This file is part of Redqueen.
#
# Sergej Schumilo, 2019 <sergej@schumilo.de> 
# Cornelius Aschermann, 2019 <cornelius.aschermann@rub.de> 
# 
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Redqueen.  If not, see <http://www.gnu.org/licenses/>.
#

mount -t proc none /proc
mount -t sysfs none /sys
mount -t debugfs none /sys/kernel/debug
mount -t devtmpfs none /dev
mount -t tmpfs none /tmp
chmod 777 / /tmp

echo "7" > /proc/sys/kernel/printk
echo "0" >  /proc/sys/kernel/printk_ratelimit 
echo "19999999" >  /proc/sys/kernel/printk_ratelimit_burst
echo "1" > /proc/sys/kernel/panic_on_oops


# set cmdline as script arguments, then eval() anything we recognize
set -- $(cat /proc/cmdline)
for arg in "$@"; do
	case "$arg" in
		kafl_agent=*)
			eval "$arg"
			;;
	esac
done

# if kafl_agent points to valid executable, assume this is the intended target
test -x "$kafl_agent" && exec $kafl_agent

# fallback: launch option set by pack.sh
/default_agent

